{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\conda\\envs\\evaluate_env\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "# step1 导入相关包 & 设置镜像\n",
    "import evaluate\n",
    "import os\n",
    "os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'accuracy': 0.5}\n"
     ]
    }
   ],
   "source": [
    "# Example 1\n",
    "\n",
    "accuracy_metric = evaluate.load(\"accuracy\")\n",
    "results = accuracy_metric.compute(\n",
    "    references=[0, 1, 2, 0, 1, 2],\n",
    "    predictions=[0, 1, 1, 2, 1, 0]\n",
    ")\n",
    "print(results)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'accuracy': 3.0}\n"
     ]
    }
   ],
   "source": [
    "# Example 2\n",
    "accuracy_metric = evaluate.load(\"accuracy\")\n",
    "results = accuracy_metric.compute(\n",
    "    references=[0, 1, 2, 0, 1, 2],\n",
    "    predictions=[0, 1, 1, 2, 1, 0],\n",
    "    normalize=False\n",
    ")\n",
    "print(results)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'accuracy': 0.8778625954198473}\n"
     ]
    }
   ],
   "source": [
    "# Example 3\n",
    "\n",
    "accuracy_metric = evaluate.load(\"accuracy\")\n",
    "results = accuracy_metric.compute(\n",
    "  references=[0, 1, 2, 0, 1, 2], \n",
    "  predictions=[0, 1, 1, 2, 1, 0], \n",
    "  sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4]\n",
    ")\n",
    "print(results)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "evaluate_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "37990cb7e14a4280d29cc47a919e2d55f3bfd74dc413cee212f628168b6511e1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
